/**********************************
**** This file will read in the public use data set for the
	2019 Survey of American Science teachers and reproduce tables
	published in:
	
		Plutzer, Eric, Glenn Branch and Ann Reid. 2020. 
		"Teaching Evolution in U.S. Public Schools: A Continuing Challenge."  
		Evolution: Education and Outreach 13:14 
		(https://doi.org/10.1186/s12052-020-00126-8).
*/


***********************************************************
**** NOTE: TABLE COMMANDS WILL NOT RUN IN STATA 17
****       To replicate published tables, the version command
****       must be executed.
****       This file will run without error if executed in its
****       entirety.  Otherwise, the version command must be 
****       executed before each table request.

version 16

use 2019_Survey_of_American_Science_Teachers_PUS_dataset.dta




keep if level==2

* Activate weighting for analyses using the SVY prefix.
svyset [pw=final_weight]


**** Table 1. Time devoted to evolution
svy: tabulate q1_generalevo  , missing percent stubw(30)
svy: tabulate q1_humanevo  , missing percent stubw(30)


svy: mean q1_num_generalevo if q1_any_generalevo==1  
svy: mean q1_num_humanevo if q1_any_humanevo==1 

**** Table 2. Emphasis in class
svy: tabulate q2_evo_noevolution,  missing percent stubw(30)
svy: tabulate q2_evo_theme,  percent stubw(30)
svy: tabulate q2_evo_consensus,  percent stubw(30)

**** Table 3. Time devoted to evolution
svy: tabulate q1_idcreat  , missing percent stubw(30) format(%9.2f)

**** Table 4. View concerning creationism
svy: tabulate q2_evo_intelligentdesign , missing percent stubw(30) format(%9.2f)
svy: tabulate q2_evo_idvalidalt , missing percent stubw(30) format(%9.2f)

gen id_summary = 0
replace id_summary = 1 if (q2_evo_intelligentdesign <= 2 | 			q2_evo_idvalidalt <=2)
replace id_summary = 2 if (q2_evo_intelligentdesign <= 2 & 			q2_evo_idvalidalt <=2)

svy: tabulate id_summary , missing percent stubw(30) format(%9.2f)


*************** CONSTRUCT TYPOLOGY *****************

* 1 generate ordinal measures
gen creat_ordinal_1 = 0
replace creat_ordinal_1 = 1 if q2_evo_intelligentdesign == 2 // agree
replace creat_ordinal_1 = 2 if q2_evo_intelligentdesign == 1 // agree strongly

gen creat_ordinal_2 = 0
replace creat_ordinal_2 = 1 if q2_evo_idvalidalt == 2 // agree
replace creat_ordinal_2 = 2 if q2_evo_idvalidalt == 1 // agree strongly

egen creat_ordinal = rowmax(creat_ordinal_1 creat_ordinal_2)

***  labeling
label define ord  0 "Agrees with neither statement"
label define ord  1 "Agrees with at least one", add
label define ord  2 "Strongly agrees with at least one", add
label values creat_ordinal ord

*
gen evo_ordinal_1 = 0
replace evo_ordinal_1 = 1 if q2_evo_consensus == 2 // agree
replace evo_ordinal_1 = 2 if q2_evo_consensus == 1 // agree strongly

gen evo_ordinal_2 = 0
replace evo_ordinal_2 = 1 if q2_evo_theme == 2 // agree
replace evo_ordinal_2 = 2 if q2_evo_theme == 1 // agree strongly

gen evo_ordinal = evo_ordinal_1 + evo_ordinal_2


tab evo_ordinal_1 creat_ordinal if level == 2 & hs_chem_other==0 [aw=final_weight], missing cell

gen evo_free_discussion = 0
replace evo_free_discussion = 1 if q3_discussion == 1
replace evo_free_discussion = . if q3_discussion == .


*** PROFILES
gen new_typology = .
replace new_typology = 1 if (evo_ordinal_1 ==1 | evo_ordinal_1 ==2)  & ///
	creat_ordinal ==0
replace new_typology = 2 if (evo_ordinal_1 ==1 | evo_ordinal_1 ==2) & ///
	(creat_ordinal ==1 | creat_ordinal ==2) 
replace new_typology = 3 if evo_ordinal_1 ==0 & ///
	creat_ordinal ==0
replace new_typology = 4 if evo_ordinal_1 ==0 & ///
	(creat_ordinal ==1 | creat_ordinal ==2) 

*** Setup for labeling
label define prof  1 "Evolution as settled science"
label define prof  2 "Mixed messages", add
label define prof  3 "Avoidance", add
label define prof  4 "Creationism", add


*** FOR FIGURE 1 ***
svy: tabulate new_typology  , percent stubw(30) format(%9.2f) se ci deft
svy: tabulate new_typology  , count stubw(30) format(%9.1f)
*
* Table 5. NGSS
svy: tabulate new_typology ngss_level  , col stubw(30) format(%9.2f) percent 
svy: tabulate new_typology ngss_level , count


* Table 6. Seniority
svy: tabulate new_typology teachingin_2007  , col stubw(30) format(%9.2f) percent
svy: tabulate new_typology teachingin_2007, count

* Table 7. Hours by NGSS and seniority

*a
table teachingin_2007 ngss_level    [aweight = final_weight], contents(mean q1_num_gen) row format(%9.2f) stubwidth(30)

table teachingin_2007 ngss_level    [aweight = final_weight], contents(mean q1_num_gen freq ) row format(%9.2f) stubwidth(30)

* Establish significance
svy: reg q1_num_generalevo i.teachingin_2007 i.ngss_level  
svy: reg q1_num_generalevo i.teachingin_2007##i.ngss_level 

*b
table teachingin_2007 ngss_level    [aweight = final_weight], contents(mean q1_num_humanevo ) row format(%9.2f) stubwidth(30)

svy: reg q1_num_humanevo teachingin_2007 i.ngss_level   
svy: reg q1_num_humanevo i.teachingin_2007##i.ngss_level  

*c
table teachingin_2007 ngss_level  [aweight = final_weight], contents(mean q1_num_idcreat) row format(%9.2f) stubwidth(30) 
svy: reg q1_num_idcreat teachingin_2007 i.ngss_level   
svy: reg q1_num_idcreat i.teachingin_2007##i.ngss_level


*********************************************************************
****** COLLEGE CLASS IN EVOLUTION ******


* Collapse 3 and 4 or more:
clonevar evo_college_3 = q27_evo_college
replace  evo_college_3 = 4 if  evo_college_3 == 5
tab  evo_college_3 q27_evo_college, nolabel

clonevar evo_section_3 = q27_sectionevo_college
replace evo_section_3 = 4 if evo_section_3 == 5
tab evo_section_3 q27_sectionevo_college, nolabel

clonevar evo_conted_3 = q27_evo_conted
replace evo_conted_3 = 4 if evo_conted_3 == 5
tab evo_conted_3 q27_evo_conted, nolabel

* Table 8a
svy: tabulate new_typology evo_college_3    ,  percent format(%9.2f) stubw(33) col 

*Table 8.b
svy: tabulate new_typology evo_section_3    ,  percent format(%9.2f) stubw(33) col 

*Table 8.c
svy: tabulate new_typology evo_conted_3    ,  percent format(%9.2f) stubw(33) col 



gen total_hours = q1_num_generalevo + q1_num_humanevo

**** Table 9 (columns reversed in published article)
* Table 9a
table ngss_level teachingin   [aweight = final_weight], contents(mean q27_evo_college  ) format(%9.2f) stubwidth(25)

svy: reg q27_evo_college teachingin_2007 i.ngss_level   
svy: reg q27_evo_college i.teachingin_2007##i.ngss_level

*Table 9b
table ngss_level teachingin   [aweight = final_weight], contents(mean q27_sectionevo_col  ) format(%9.2f) stubwidth(25)

svy: reg q27_sectionevo_col teachingin_2007 i.ngss_level   
svy: reg q27_sectionevo_col i.teachingin_2007##i.ngss_level

*Table 9c
table ngss_level teachingin   [aweight = final_weight], contents(mean q27_evo_conted  ) format(%9.2f) stubwidth(25)

svy: reg q27_evo_conted teachingin_2007 i.ngss_level   
svy: reg q27_evo_conted i.teachingin_2007##i.ngss_level

**** Table 10

gen young_earther = .
replace young_earther = 1 if q16_origin == 3
replace young_earther = 0 if q16_origin <= 2

gen literal = .
replace literal = 0 if q31_bible == 2 | q31_bible == 3
replace literal = 1 if q31_bible == 1



table new_typology    [aweight = final_weight], contents(mean young_earther mean literal freq) row format(%9.3f) stubwidth(30)









